﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Dynamic;
using System.Linq;
using System.Text;
using Trade.DBUtility;
using Trade.DBUtility.DataTableName;

namespace Trade.DBUtility
{
    public class Common
    {
        public class decimalEx
        {
            public static decimal RoundEx(decimal decValue, int decimals)
            {
                return decimal.Round(decValue, decimals, MidpointRounding.AwayFromZero);
            }
        }
        public static DateTime GetServerTime()
        {
            DateTime dtimeCatch;
            DataTableName.DataTableName dtnTime = new DataTableName.DataTableName();
            dtnTime.strSelectSQL = "SELECT GetDate()";
            dtnTime.strTableName = "T_DataTime";
            DataSet dsTime = null;
            try
            {
                dsTime = CustomizableDesignBLL.GetData(dtnTime, false);
            }
            catch
            {
                return DateTime.Now;
            }
            if (dsTime == null || dsTime.Tables.Count <= 0 || dsTime.Tables[0].DefaultView.Count <= 0)
            {
                dtimeCatch = DateTime.Now;
            }
            else
            {
                dtimeCatch = dsTime.Tables[0].DefaultView[0][0] == DBNull.Value ? DateTime.Now : (DateTime)dsTime.Tables[0].DefaultView[0][0];
            }
            return dtimeCatch;
        }


        public static DateTime GetServerDate()
        {
            DateTime dtimeCatch;
            DataTableName.DataTableName dtnTime = new DataTableName.DataTableName();
            dtnTime.strSelectSQL = "SELECT GetDate()";
            dtnTime.strTableName = "T_DataTime";
            DataSet dsTime = null;
            try
            {
                dsTime = CustomizableDesignBLL.GetData(dtnTime, false);
            }
            catch
            {
                return DateTime.Now.Date;
            }
            if (dsTime == null || dsTime.Tables.Count <= 0 || dsTime.Tables[0].DefaultView.Count <= 0)
            {
                dtimeCatch = DateTime.Now.Date;
            }
            else
            {
                dtimeCatch = dsTime.Tables[0].DefaultView[0][0] == DBNull.Value ? DateTime.Now.Date : (DateTime)dsTime.Tables[0].DefaultView[0][0];
            }
            return dtimeCatch;
        }
        /// <summary>
        /// 根据帐套获取数据库名称
        /// </summary>
        /// <param name="strCode">帐套号</param>
        /// <returns></returns>
        public static string GetdatabaseName(string strCode)
        {
            // string strDataBase = "UFDATA_" + strCode + "_2014";
            //string strDataBase = "UFDATA_" + strCode + "_2016";
            //return strDataBase;
            string strDataBase = ConfigurationManager.AppSettings["U8DataBase"];
            return strDataBase;
        }
        public static string getU8SerVerIP()
        {
            string strConnectString = ConfigurationManager.AppSettings["U8APIIP"];// ConfigurationManager.ConnectionStrings["U8APIIP"].ConnectionString;
            return strConnectString;
        }
        public static bool getBisTest()
        {
            // ConfigurationManager.ConnectionStrings["U8APIIP"].ConnectionString;
            string strTest = ConfigurationManager.AppSettings["Test"];
            return !string.IsNullOrEmpty(strTest);
        }

    }
}
